package cn.com.css.taxInspection;

import cn.com.css.taxInspection.common.config.SnowflakeIdWorker;
import cn.com.css.taxInspection.common.config.TaxInspectionConfig;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableScheduling;

import javax.annotation.Resource;
import java.net.InetAddress;
import java.net.UnknownHostException;

@Slf4j
@SpringBootApplication(exclude = {DruidDataSourceAutoConfigure.class, FreeMarkerAutoConfiguration.class})
@MapperScan({"cn.com.css.taxInspection.system.mapper", "cn.com.css.taxInspection.workflow.mapper",
        "cn.com.css.taxInspection.gt3.mapper", "cn.com.css.taxInspection.workrisk.mapper",
        "cn.com.css.taxInspection.attention.mapper", "cn.com.css.taxInspection.statistics.mapper",
        "cn.com.css.taxInspection.thirdparty.mapper", "cn.com.css.taxInspection.zdgz.mapper",
        "cn.com.css.taxInspection.xtgl.mapper", "cn.com.css.taxInspection.zzgl.mapper"})
@EnableScheduling // 启用定时任务支持
public class TaxInspectionApplicationStart {

    @Resource
    private TaxInspectionConfig taxInspectionConfig;

    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext application = SpringApplication.run(TaxInspectionApplicationStart.class, args);
        log.info("-------------启动成功------------");
        Environment env = application.getEnvironment();
        log.info("\n----------------------------------------------------------\n\t"
                        + "Application '{}' is running! Access URLs:\n\t" + "Login: \thttp://{}:{}/login\n\t"
                        + "Doc: \thttp://{}:{}/doc.html\n" + "----------------------------------------------------------",
                env.getProperty("spring.application.name"), InetAddress.getLocalHost().getHostAddress(),
                env.getProperty("server.port"), InetAddress.getLocalHost().getHostAddress(),
                env.getProperty("server.port"));
    }

    @Bean
    public SnowflakeIdWorker snowflakeIdWorker() {
        return new SnowflakeIdWorker(taxInspectionConfig.getWorkerId(), taxInspectionConfig.getDatacenterId());
    }

}
